

package examples.radio;

import commandz.cli.*;
import commandz.var.*;
import java.io.IOException;
import java.util.Collection;


/**
 *  Loads a radio preset.
 */
public final class LoadCommand implements Command
{
    private VariableString preset;
    private Radio radio;


    public LoadCommand(Radio radio)
    {
        this.radio = radio;
        this.preset = new VariableString();
    }


    public String getName()
    {
        return "load";
    }


    public String getDescription()
    {
        return "Loads a given preset.";
    }


    public void publishParameters(Collection<Parameter> params)
    {
        params.add(new Parameter(this.preset, "filename", "The filename of a preset."));
    }


    public void execute()
    {
        String filename = this.preset.getValue();

        try // to load settings...
        {
            this.radio.load(filename);
        }
        catch (IOException error)
        {
            System.out.println(error.getMessage());
            return;
        }

        System.out.printf("Receiving %.2f %s, volume %d.\n",
            this.radio.getFrequency(), this.radio.getModulation(), this.radio.getVolume());
    }
}
